package com.spsoft.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spsoft.system.entity.NvatNegativestream;
import com.spsoft.system.mapper.NvatNegativestreamMapper;
import com.spsoft.system.service.NvatNegativestreamService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 负数流水管理表 服务实现类
 * </p>
 *
 * @author dingchengyun
 * @since 2024-02-26
 */
@Service
@RequiredArgsConstructor
public class NvatNegativestreamServiceImpl extends ServiceImpl<NvatNegativestreamMapper, NvatNegativestream> implements NvatNegativestreamService {

    private final NvatNegativestreamMapper nvatNegativestreamMapper;
    @Override
    public boolean rollbackByRdids(List<Long> wkpRdidList) {
        return nvatNegativestreamMapper.rollbackByRdids(wkpRdidList);
    }

    @Override
    public boolean updateByRdids(List<Long> wkpRdidList, String dataSource) {
//        处理状态=0（未处理）的数据，处理状态=1（已处理）、处理类型=5（负数流水开票）、处理人=官网开票、处理时间=当前日期、处理说明=官网开票
        LambdaUpdateWrapper<NvatNegativestream> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(NvatNegativestream::getClzt, "1")
                .set(NvatNegativestream::getCllx, "5")
                .set(NvatNegativestream::getCzr, dataSource)
                .set(NvatNegativestream::getCzrq, new Date())
                .set(NvatNegativestream::getCzsm, dataSource)
                .in(NvatNegativestream::getRdid, wkpRdidList)
                .eq(NvatNegativestream::getClzt, "0");
        return super.update(wrapper);
    }

    @Override
    public List<NvatNegativestream> getByClztYwbh(String ywbh) {
        LambdaQueryWrapper<NvatNegativestream> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(NvatNegativestream::getClzt, "0")
                .eq(NvatNegativestream::getYwbh,ywbh);
        return super.list(wrapper);
    }

}
